<!DOCTYPE html>
<html lang="pt-BR">
    <head>
        <?php
        session_start();
        include_once'bloco/head.php';
        include_once '../control/conexao.php';
        include_once '../control/valida_sessao.php';

        function __autoload($classe) {
            include_once"../model/{$classe}.class.php";
        }
        ?>
        <link href="bootstrap/css/morris.css" rel="stylesheet">
    </head>
    <body>      
        <div id="wrapper">
            <?php
            include_once'bloco/navbar.php';
            include_once '../control/valida_perfil.php';
            ?>
            <div id="page-wrapper">
                <?php include_once 'bloco/banner.php'; ?>                  
                <div class="row">
                    <div class=" panel panel-success">
                        <div class="panel-heading">
                            <p class="panel-title"><i class = "glyphicon glyphicon-th-large"></i> Editar Funcionario</p>
                        </div>
                        <div class="panel-body">
                            <div class="col-lg-12 ">
                                <form autocomplete="off" name="form_edita_funcionario" method="post" action="../control/editar_funcionario.php">
                                    <div class="row">
                                        <div class="col-md-6 col-md-offset-3">
                                            <div class="alert alert-success alert-dismissable">
                                                <table class="table table-condensed table-responsive">                                    
                                                    <?php
                                                    $funcionario = new usuario();
                                                    $funcionario->id_usuario = $_GET['id'];
                                                    $usuarioDAO = new usuarioDAO();
                                                    $funcionario = $usuarioDAO->consultar($funcionario);
                                                    ?>
                                                    <tr>
                                                        <td><strong>Senha</strong></td>                                        
                                                        <td><input type="password" name="senha" class="form-control" required value="<?php echo utf8_encode($funcionario->usuario_senha) ?>"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td><strong>Nome</strong></td>
                                                        <td><input type="text" name="nick" class="form-control" required="" value="<?php echo utf8_encode($funcionario->usuario_nick) ?>"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td><strong>Login</strong></td>
                                                        <td><input type="text" name="login" class="form-control" required="" value="<?php echo utf8_encode($funcionario->usuario_login) ?>"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <label>Perfil</label>
                                                        </td>
                                                        <?php
                                                        $consulta = mysql_query("SELECT * FROM perfil WHERE id_perfil = '$funcionario->id_perfil'");
                                                        $perfil = mysql_result($consulta, 0, "perfil_nome");

                                                        $consulta_perfis = mysql_query("SELECT * FROM perfil WHERE id_perfil='0' || id_perfil='2' order by perfil_nome");
                                                        $ln = mysql_num_rows($consulta_perfis);
                                                        ?>
                                                        <td>
                                                            <select name="perfil" class='btn btn-block'>                                
                                                                <option value="<?php echo $funcionario->id_perfil ?>"><?php echo ">>> " . utf8_encode($perfil) . " <<<"; ?></option>
                                                                <?php
                                                                for ($i = 0; $i < $ln; $i++) {
                                                                    $id_perfil = mysql_result($consulta_perfis, $i, "id_perfil");
                                                                    $perfil_nome = mysql_result($consulta_perfis, $i, "perfil_nome");
                                                                    ?>
                                                                <option value="<?php echo $id_perfil ?>"><?php echo utf8_encode($perfil_nome) ?></option>
                                                                <?php } ?>
                                                            </select>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <input type="hidden" name="id_usuario" value="<?php echo $funcionario->id_usuario ?>">
                                                <div align="center">
                                                    <input type="button" class="btn btn-inverse" value="Voltar" onclick="history.go(-1)"/>
                                                    <input type="submit" class="btn btn-success" value="Salvar"/>
                                                </div>
                                            </div>
                                        </div>                                       
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
        include_once'bloco/scripts.php';
        ?>        
    </body>
</html>